package num;

/**
 * @program: data_structures_algorithms
 * @description: 判断一个数是否为2的整数次幂
 * @author: lld
 * @create: 2020-11-14 19:54
 **/
public class PowerOf2 {
    public static void main(String[] args) {
        System.out.println(isPowerOf2(8));
        System.out.println(isPowerOf2(10));
    }
    public static boolean isPowerOf2(int n){
        /*&位与运算
        *    8        10
        *  1000     1010
        * -0001    -0001
        * =0111    =1001
        *
        *  1000     1010
        * &0111    &1001
        * =0000     1000
        **/
        return (n&(n-1))==0;
    }
}
